<?php
namespace App\Admin\Exporter;

use App\Admin\Repositories\AdminApply;
use Illuminate\Support\Collection;

class ApplyExport extends BaseExporter
{

   public function typeName(): string
   {
       return '报名表';
   }

   protected function data($list): array
   {
       $data = [
           [
               'sheet_name' => $this->typeName(),
               'data' => []
           ]
       ];
       foreach ($list as $v) {
           $orderRow = $v;
           $data[0]['data'][] =  $this->addOrderRow($orderRow);;
       }
       return $data;
   }

   protected function title(): array
   {
        return [
            [
                'children'=>[
                    [
                        'field' => 'user_name',
                        'name' => '姓名',
                        'width' => 20
                    ],
                    [
                        'field' => 'status',
                        'name' => '状态',
                        'width' => 20
                    ],
                    [
                        'field' => 'id_card_number',
                        'name' => '身份证号',
                        'width' => 40
                    ],
                    [
                        'field' => 'phone',
                        'name' => '电话',
                        'width' => 20
                    ],
                    [
                        'field' => 'source',
                        'name' => '来源',
                        'width' => 20
                    ],
                    [
                        'field' => 'work_type',
                        'name' => '工种',
                        'width' => 20
                    ],
                    [
                        'field' => 'level',
                        'name' => '等级',
                        'width' => 20
                    ],
                    [
                        'field' => 'work_experience',
                        'name' => '工作经历',
                        'width' => 20
                    ],
                    [
                        'field' => 'age',
                        'name' => '年龄',
                        'width' => 10
                    ],
                    [
                        'field' => 'sex',
                        'name' => '性别',
                        'width' => 10
                    ],
                    [
                        'field' => 'card_front_image',
                        'name' => '身份证正面',
                        'width' => 20
                    ],
                    [
                        'field' => 'card_back_image',
                        'name' => '身份证反面',
                        'width' => 20
                    ],
                    [
                        'field' => 'head_image',
                        'name' => '一寸登记照',
                        'width' => 20
                    ],
                    [
                        'field' => 'diploma_image',
                        'name' => '毕业证或学历备案表',
                        'width' => 20
                    ],
                    [
                        'field' => 'social_security_image',
                        'name' => '社保证明',
                        'width' => 20
                    ],
                    [
                        'field' => 'skill_image',
                        'name' => '职业技能等级证书',
                        'width' => 20
                    ],
                    [
                        'field' => 'company',
                        'name' => '公司',
                        'width' => 20
                    ],
                    [
                        'field' => 'created_at',
                        'name' => '创建时间',
                        'width' => 20
                    ],
                    [
                        'field' => 'updated_at',
                        'name' => '修改时间',
                        'width' => 20
                    ],
                ]
            ]
        ];
   }

    protected function addOrderRow(array $data): array
    {
        return [
            'user_name'=>$data['user_name'] ??'',
            'status'=>AdminApply::STATUS[$data['status']],
            'id_card_number'=>(string)($data['id_card_number'] ??''),
            'phone'=>$data['phone'] ?? '',
            'source'=>$data['source'] ?? '',
            'work_type'=>$data['work_type'] ?? '',
            'level'=>$data['level'] ?? '',
            'work_experience'=>$data['work_experience'] ?? '',
            'card_front_image'=>env('APP_URL').($data['card_front_image'] ?? ''),
            'card_back_image'=>env('APP_URL').($data['card_front_image'] ?? ''),
            'head_image'=>env('APP_URL').($data['head_image'] ?? ''),
            'diploma_image'=>env('APP_URL').($data['diploma_image'] ?? ''),
            'social_security_image'=>env('APP_URL').($data['social_security_image'] ?? ''),
            'skill_image'=>empty($data['social_security_image'])?'':env('APP_URL').$data['skill_image'],
            'age'=>$data['age'] ?? '',
            'sex'=>($data['sex']==1)?'男':'女',
            'company'=>$data['company'] ?? '',
            'created_at'=>$data['created_at'] ?? '',
            'updated_at'=>$data['updated_at'] ?? ''
        ];
    }
}
